//
//  MoviePlayViewController.m
//  shipin
//
//  Created by lanou3g on 15/11/19.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "MoviePlayViewController.h"

#import <MediaPlayer/MediaPlayer.h>
@interface MoviePlayViewController ()

@property (nonatomic, strong) MPMoviePlayerController *player;

@end

@implementation MoviePlayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadPlayer];
}
- (void)loadPlayer{
    _player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:self.mp4_url]];
    _player.view.frame = self.view.frame;
    //设置视频播放的适配
    _player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    _player.controlStyle = MPMovieControlStyleEmbedded;
    [self.view addSubview:_player.view];
    //播放视频
    [_player play];
    //监听Done的时间
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exit) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
    
    //播放结束的时候退出来
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exit) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    
}

- (void)exit
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
